package com.hand.endpoint;

import com.hand.dao.CountryRepository;
import com.hand.entity.GetCountriesRequest;
import com.hand.entity.GetCountriesResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

/*******************Copyright Information************************
 *              AUTHOR: Lorin.Mitchell                           *
 *              DATE: 2017/11/7                                 *
 *              TIME: 19:27                                      *
 ****************************************************************/
@Endpoint
public class CountriesEndpoint {
    private static final String NAMESPACE_URI = "http://www.hand-china.com";

    @Autowired
    private CountryRepository countryRepository;

    //@PayloadRoot注解，表示该方法将处理以namespace和localPart的xml请求信息
    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountriesRequest")
    //@ResponsePayload注解，表示将返回值映射到reponse中
    @ResponsePayload
    public GetCountriesResponse getCountries(@RequestPayload GetCountriesRequest request) {
        GetCountriesResponse response = new GetCountriesResponse();
        response.setCountries(countryRepository.findCountries());

        return response;
    }
}
